package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetMealMapper extends BaseMapper<Setmeal> {
    @Insert("insert into t_setmeal_checkgroup values(#{setmeal_pk},#{checkgroupid})")
    void addSetMealAndCheckGroupInfos(@Param("setmeal_pk") int setmeal_pk, @Param("checkgroupid") Integer checkgroupid);

    @Delete("delete from t_setmeal_checkgroup where setmeal_id = #{id}")
    void deleteCheckGroupInfoBySetmealId(@Param("id") Integer id);

    @Select("select checkgroup_id  from t_setmeal_checkgroup where setmeal_Id = #{gid}")
    int[] findCheckGroupInfoBySetmealId(@Param("gid") int gid);

    @Select("select name,age,remark,img,sex from t_setmeal where id = #{id}")
    SetmealVO findSetmealById(@Param("id") int id);

    @Select("SELECT tc.id, tc.name ,tc.remark " +
            "FROM  t_setmeal_checkgroup  tsc , t_checkgroup tc " +
            "WHERE  tc.id = tsc.CHECKGROUP_ID " +
            "and tsc.SETMEAL_ID = #{id}")
    List<CheckGroupVO> findCheckGroupInfosBySetmealId(@Param("id") int id);
    @Select("SELECT tc.name " +
            "FROM  t_checkgroup_checkitem tcc , t_checkitem tc " +
            "WHERE tcc.CHECKITEM_ID = tc.ID " +
            "and tcc.CHECKGROUP_ID = #{id}")
    List<CheckItem> findCheckItemsByCheckGroupId(@Param("id") Integer id);
}
